﻿namespace HelloKinkuma.Silverlight
{
    using System.ComponentModel.DataAnnotations;
    using Microsoft.Practices.Prism.Commands;
    using Microsoft.Practices.Prism.Interactivity.InteractionRequest;
    using Okazuki.MVVM.PrismSupport.Utils;
    using Okazuki.MVVM.PrismSupport.ViewModels;

    public class MainPageViewModel : ValidatableViewModelBase
    {
        private string input;

        [Required(ErrorMessage = "入力してね")]
        public string Input
        {
            get
            {
                return this.input;
            }

            set
            {
                this.input = value;
                this.RaisePropertyChanged(() => Input);
            }
        }

        public MainPageViewModel()
        {
            this.ValidateProperties();
        }

        [AutoInitCommand]
        public DelegateCommand GreetCommand { get; set; }

        [AutoInit]
        public InteractionRequest<Notification> AlertRequest { get; set; }

        [CommandMethod]
        public void GreetExecute()
        {
            this.AlertRequest.Raise(new Notification { Content = this.Input });
        }

        [CommandMethod]
        public bool CanGreetExecute()
        {
            return !this.HasErrors;
        }
    }
}
